package thread;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-13
 * Time: 18:18
 */
public class demo9 {
    private static boolean running = true;
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while(running){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t线程结束");
        });
        t.start();
        // 主线程中, 让用户进行输入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入整数, 0 表示让 t 线程终止");
        int n = sc.nextInt();
        if(n == 0){
            running = false;

        }

    }
}
